package utility;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Hashtable;
import dbmanager.DBManager;

public class ReplacesSpecialCharacter
{
	DBManager db;
	
	final String MSGTYPE="msgtype";
	final String COMMAND="command";
	final String FIELDNAME ="fieldname";
	final String SPCHAR ="spchar";
	
	public ReplacesSpecialCharacter(DBManager db) 
	{
		this.db =db;
	}
	
	public  Hashtable< Object, Object> ReplacesChar(String tablename,Hashtable<Object, Object >map,String process)
	{
		map = ConvertToLower.convertHashKey(map);
		Hashtable< Object, Object>htable = new Hashtable<Object, Object>();
		htable.put(MSGTYPE,tablename);
		htable.put("process", process);
		ResultSet rs =db.getselect(htable, COMMAND);
		htable.clear();
		htable.putAll(map);
		try 
		{
			while(rs.next())
			{
				try 
				{
					String Fieldname = rs.getString(FIELDNAME).toLowerCase();
					if(map.containsKey(Fieldname))
					{
						htable.put(rs.getString(SPCHAR),map.get(Fieldname));
						htable.remove(Fieldname);
					}
				}
				catch (Exception e) {
				}
			}
		} 
		catch (SQLException e) 
		{
			System.out.println("Exception in Utility::ReplacesSpecialChararter::ReplacesChar ->SQLException" );
			e.printStackTrace();
		}
		return htable;
	}
	public static void main(String[] args) 
	{	
		DBManager db = new DBManager();
		db.getConnect();
		ReplacesSpecialCharacter rsc = new ReplacesSpecialCharacter(db);
		Hashtable<Object, Object>map = new Hashtable<Object, Object>();
		map.put("Conditionoperator","123");
		map.put("Conditionvalue","12");
		map.put("MN","21");
		//System.out.println(rsc.ReplacesChar("Condition", map));
	}
}
